package jym.tan.movielibrary;

import javax.swing.SwingUtilities;

import jym.tan.movielibrary.configuration.ConfigurationManager;
import jym.tan.movielibrary.configuration.run.RunManager;
import jym.tan.movielibrary.factory.ComponentFactory;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.GenericApplicationContext;

public class Launcher {

	public static void main(String[] args) throws Exception {
		DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
		BeanDefinition beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(RunManager.class).addConstructorArgValue(args).getBeanDefinition();
		beanFactory.registerBeanDefinition("runManager", beanDefinition);
		GenericApplicationContext genericApplicationContext = new GenericApplicationContext(beanFactory);
		genericApplicationContext.refresh();
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[] { "application-context.xml" }, genericApplicationContext);		
		
		ConfigurationManager.setApplicationContext(applicationContext);
		ConfigurationManager.getInstance().getConfiguration().getUiManager().setDefaultTheme();
		
		SwingUtilities.invokeLater(new Runnable() {

			public void run() {
				ComponentFactory.getLibraryFrame().setVisible(true);
			}
		});
	}
}
